package com.station.search.plugin.inlist;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: JT
 * @date: 2021/8/31
 * @Title:
 */
public class InListValidator implements ConstraintValidator<InList, String> {

    private boolean isRequired = false;
    private List<String> strList = new ArrayList<>();

    @Override
    public void initialize(InList inList) {
        isRequired = inList.required();
        strList = Arrays.asList(inList.list());
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return strList.contains(value);
    }
}
